package com.chen.user.controller;


import com.chen.user.common.Result;
import com.chen.user.entity.Comment;
import com.chen.user.service.CommentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class CommentController {

    @Autowired
    private CommentService commentService;


    @GetMapping("/getCommentPage/{id}")
    public Result<PageInfo> getCommentPage(@PathVariable int id, @RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
       List<Comment> commentList= commentService.getCommentPage(id);
       return Result.success(PageInfo.of(commentList));

    }


    /**
     * 添加评论
     * @return
     */
    // 添加评论
    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment) {
         Result result=commentService.addComment(comment);
        return result;
    }

}
